﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BlogManager
{
    public partial class AddForm : Form
    {

        public event Action<Blog> ReturnHandler;

        public AddForm()
        {
            InitializeComponent();
        }


        public Blog Content
        {
            set
            {
                txt_password.Text = value.blogPassowod;
                txt_blogUrl.Text = value.blogUrl;
                txt_title.Text = value.blogTitle;
                txt_username.Text = value.blogUsername;
                cb_type.Text = value.blogType;
                txt_keyword.Text = value.blogKeyword;
                txt_desc.Text = value.blogDesc;
            }
        }
        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (safeCheck() == true)
            {
                string blogurl = txt_blogUrl.Text;
                string blogtitle = txt_title.Text;
                string blogtype = cb_type.Text;
                string blogusername = txt_username.Text;
                string blogpassword = txt_password.Text;
                string blogDesc=txt_desc.Text;
                string blogKeyword=txt_keyword.Text;
                     

                Blog b = new Blog();
                b.blogUrl = blogurl;
                b.blogTitle = blogtitle;
                b.blogType = blogtype;
                b.blogPassowod = blogpassword;
                b.blogUsername = blogusername;
                b.blogKeyword = blogKeyword;
                b.blogDesc = blogDesc;
                ///回调函数
                if (this.ReturnHandler != null )
                {
                    this.ReturnHandler(b);
                }

            }
            else
            {
                MessageBox.Show("數據填寫不完整！請檢查一下哦！");
                return;
            }

            this.Dispose();

        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }


        private bool safeCheck()
        {
            if (txt_blogUrl.Text.Trim() != "" && txt_title.Text.Trim() != "" && txt_username.Text.Trim() != "" && txt_password.Text.Trim() != "")
            { 
                return true; 
            }
            else
            {
                return false; 
            } 
        }
    }
}
